import datetime
import calendar

def lastday_of_lastmonth(day):
    '''在当日计算上月第一日&最后一日日期'''
    if day.month>1:
        _, last = calendar.monthrange(day.year, day.month-1)    
        firstdate = datetime.date(day.year, day.month-1, 1).strftime('%Y-%m-%d')
        lastdate = datetime.date(day.year, day.month-1, last).strftime('%Y-%m-%d')
    else: 
        year = day.year-1
        _, last = calendar.monthrange(year, 12)
        firstdate = datetime.date(year, 12, 1).strftime('%Y-%m-%d')
        lastdate = datetime.date(year, 12, last).strftime('%Y-%m-%d')

    return firstdate,lastdate